package com.cn.wanxi.service;

import com.cn.wanxi.dao.NewsDao;
import com.cn.wanxi.model.NewsModel;

import java.util.ArrayList;
import java.util.List;

public class NewsService {
    /**
     * 能够写局部变量的时候千万不要写全局变量
     *
     * @return
     */
    public List<NewsModel> getNewsModelListForHome() {
        List<NewsModel> list = new ArrayList<>();
        NewsDao newsDao = new NewsDao();
        int length = newsDao.getContents().length;
        String[] titles = newsDao.getTitles();
        String[] contents = newsDao.getContents();
        for (int i = 0; i < length; i++) {
            NewsModel newsModel = new NewsModel();
            newsModel.setTitle(titles[i]);
            newsModel.setContent(contents[i]);
            list.add(newsModel);
        }
        return list;
    }
}
